home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Especial Multimedia
/
Especial Multimedia.iso
/
Multimed
/
Visuali
/
RESUME.ZIP
/
RESUME.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-10
|
39KB
|
1,237 lines
// RESUME.CPP Cyber-Resume
// Version 1.0, July, 1996
#include <windows.h>
#include <bwcc.h>
#include <commdlg.h>
#include <mmsystem.h>
#include <memory.h>
#include <string.h>
#include <dir.h>
#include <fstream.h>
#include <iostream.h>
#include <io.h>
#include <dos.h>
#include <mem.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <alloc.h>
#include "pcxhead.i"
#include "resume.h"
long FAR PASCAL _export WndProc(HWND,UINT,UINT,LONG);
long FAR PASCAL ChildProc(HWND,UINT,UINT,LONG);
void MoveCaret(HWND,int,int,int);
#define BUFFSIZE 128
#define WIDTH(x) (x.right-x.left)
#define HEIGHT(x) (x.bottom-x.top)
// This for printer
#define HORZMARGIN 0.25
#define VERTMARGIN 0.25
// This for editor
#define XSTART 10
#define YSTART 60
#define XCARETWIDTH 2
#define YCARETHEIGHT 35
#define BORDER 10
#define BORDER2 20
#define TOPBORDER 60
// WM_COMMAND values
#define MY_EDIT_RETURN 0x0401
#define MY_TEXT_BUTTON_0 0x0500
#define MY_TEXT_BUTTON_1 0x0501
#define MY_TEXT_BUTTON_2 0x0502
#define MY_TEXT_BUTTON_3 0x0503
#define MY_TEXT_BUTTON_4 0x0504
#define MY_TEXT_BUTTON_5 0x0505
#define MY_TEXT_BUTTON_6 0x0506
#define MY_TEXT_BUTTON_7 0x0507
#define MY_TEXT_BUTTON_8 0x0508
#define MY_IMAGES_BUTTON 0x0509
#define MY_IMAGE_NEXT 0x0510
#define MY_IMAGE_BACK 0x0511
#define MY_VIDEO_BUTTON 0x0512
#define MY_VIDEO_PLAY 0x0513
#define MY_VIDEO_PAUSE 0x0514
#define MY_VIDEO_REWIND 0x0515
#define MY_VOICE_BUTTON 0x0516
#define MY_EXIT 0x0517
PSTR szProgName = "Cyber-Resume for Windows";
char szAppName[32];
char szPath[BUFFSIZE] = "resume.txt";
char szTitle[BUFFSIZE];
char szString[BUFFSIZE];
char achString[BUFFSIZE];
char TextButton[9][20],ButtonTitle[20];
char images[24][16];
char captions[24][80];
RECT cRect;
HBITMAP hmemBitmap,hundomemBitmap;
HFONT hFontText;
HDC hmemDC,hundomemDC;
BOOL Shareware = FALSE;
char Text[80][80];
int nLineSpacing,nNumLines;
int VertOldPos,VertScrollPos,VertMaxScroll;
int nImageNum,nNumImages;
int ErrorMsg( HWND hwnd, char *Message )
{
MessageBox( hwnd, Message, "Error!",MB_ICONEXCLAMATION | MB_OK );
return(0);
}
BOOL GetaLine(HFILE hFile,LPSTR lineBuf,UINT *linelength)
{
int flag,count = 0;
char temp[2];
lineBuf[0] = 0x00; *linelength = 0;
do{flag = _lread(hFile,temp,1);
if (flag == HFILE_ERROR) return FALSE;
// check for CR
if (temp[0]==0x0D)
{_lread(hFile,temp,1); // skip over LF
*linelength = count;
lineBuf[count] = NULL;
break;
}
lineBuf[count++] = temp[0];
} while (flag==1);
if (flag==1) return TRUE; else return FALSE;
}
void PrintTextFile(HWND hWnd,PSTR szDocName,LPSTR szFileName)
{
HFILE hFile;
PRINTDLG pd;
DOCINFO di;
TEXTMETRIC tm;
HCURSOR hCursor,holdCursor;
char lineBuf[128],temp[128];
int yChar,yPage,yPos,xPixels,yPixels,xMargin,yMargin;
UINT linelength;
// open file
hFile = _lopen(szFileName,READ);
if (hFile == HFILE_ERROR)
{
wsprintf(temp,"\n %s file not found",szFileName);
BWCCMessageBox(hWnd,temp,"Error",MB_OK | MB_ICONINFORMATION);
return;
}
// set up PRINTDLG structure
memset(&pd,0,sizeof(PRINTDLG));
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hWnd;
pd.Flags = PD_RETURNDC | PD_NOPAGENUMS |
PD_NOSELECTION | PD_HIDEPRINTTOFILE;
// call Print common dialog
if (!PrintDlg(&pd)) return; // if NULL return foget it
// change cursor to hourglass
hCursor = LoadCursor(NULL,IDC_WAIT);
holdCursor = SetCursor(hCursor);
// print the text
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = szDocName;
di.lpszOutput = NULL;
// get text and page dimensions
GetTextMetrics(pd.hDC,&tm);
// line height in pixels
yChar = tm.tmHeight + tm.tmExternalLeading;
// page height in pixels
yPage = GetDeviceCaps(pd.hDC,VERTRES);
// pixels/in. horizontal
xPixels = GetDeviceCaps(pd.hDC,LOGPIXELSX);
// pixels/in. vertical
yPixels = GetDeviceCaps(pd.hDC,LOGPIXELSY);
// margin at left of page
xMargin = xPixels * HORZMARGIN;
// margin at top and bottom of page
yMargin = yPixels * VERTMARGIN;
/*
wsprintf(temp,"yChar=%d yPage=%d xPix=%d yPix=%d xMar=%d yMar=%d",yChar,yPage,xPixels,yPixels,xMargin,yMargin);
BWCCMessageBox(hWnd,temp,"Page Info",MB_OK | MB_ICONINFORMATION);
*/
StartDoc(pd.hDC,&di);
StartPage(pd.hDC);
yPos = yMargin;
while (GetaLine(hFile,lineBuf,&linelength))
{if (lineBuf[0]==0x0C)
{
EndPage(pd.hDC);
StartPage(pd.hDC);
yPos = yMargin;
continue;
}
TextOut(pd.hDC,xMargin,yPos,lineBuf,linelength);
yPos += yChar; // move down a line
if (yPos > yPage - yMargin - yChar)
{
EndPage(pd.hDC);
StartPage(pd.hDC);
yPos = yMargin;
}
}
_lclose(hFile);
EndPage(pd.hDC);
EndDoc(pd.hDC);
// clean up
DeleteDC(pd.hDC);
if (pd.hDevMode != NULL) GlobalFree(pd.hDevMode);
if (pd.hDevNames != NULL) GlobalFree(pd.hDevNames);
SetCursor(holdCursor); // restore cursor
}
void PrintGraphicsFile(HWND hWnd,PSTR szDocName)
{
PRINTDLG pd;
DOCINFO di;
TEXTMETRIC tm;
HCURSOR hCursor,holdCursor;
RECT cRect;
int yChar,xPage,yPage,yPos,xPixels,yPixels,xMargin,yMargin;
// char temp[80];
// set up PRINTDLG structure
memset(&pd,0,sizeof(PRINTDLG));
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hWnd;
pd.Flags = PD_RETURNDC | PD_NOPAGENUMS |
PD_NOSELECTION | PD_HIDEPRINTTOFILE;
// call Print common dialog
if (!PrintDlg(&pd)) return; // if NULL return forget it
// change cursor to hourglass
hCursor = LoadCursor(NULL,IDC_WAIT);
holdCursor = SetCursor(hCursor);
// print the screen
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = szDocName;
di.lpszOutput = NULL;
// get text and page dimensions
GetTextMetrics(pd.hDC,&tm);
// line height in pixels
yChar = tm.tmHeight + tm.tmExternalLeading;
// page width in pixels
xPage = GetDeviceCaps(pd.hDC,HORZRES);
// page height in pixels
yPage = GetDeviceCaps(pd.hDC,VERTRES);
// pixels/in. horizontal
xPixels = GetDeviceCaps(pd.hDC,LOGPIXELSX);
// pixels/in. vertical
yPixels = GetDeviceCaps(pd.hDC,LOGPIXELSY);
// margin at left of page
xMargin = xPixels * HORZMARGIN;
// margin at top and bottom of page
yMargin = yPixels * VERTMARGIN;
/*
wsprintf(temp,"yChar=%d yPage=%d xPix=%d yPix=%d xMar=%d yMar=%d",yChar,yPage,xPixels,yPixels,xMargin,yMargin);
BWCCMessageBox(hWnd,temp,"Page Info",MB_OK | MB_ICONINFORMATION);
*/
// get screen here
GetClientRect(hWnd,&cRect);
/*
wsprintf(temp,"width = %d height = %d",WIDTH(cRect),HEIGHT(cRect));
BWCCMessageBox(hWnd,temp,"Screen Info",MB_OK);
*/
SetMapMode(pd.hDC,MM_ISOTROPIC);
SetWindowExt(pd.hDC,WIDTH(cRect),WIDTH(cRect));
SetViewportExt(pd.hDC,xPage,xPage);
StartDoc(pd.hDC,&di);
StartPage(pd.hDC);
BitBlt(pd.hDC,0,0,WIDTH(cRect),HEIGHT(cRect),hmemDC,0,0,SRCCOPY);
EndPage(pd.hDC);
EndDoc(pd.hDC);
// clean up
DeleteDC(pd.hDC);
if (pd.hDevMode != NULL) GlobalFree(pd.hDevMode);
if (pd.hDevNames != NULL) GlobalFree(pd.hDevNames);
SetCursor(holdCursor); // restore cursor
}
BOOL FAR PASCAL CreateBitmapFromFile(HWND hwnd,LPSTR lpstrFile,
HBITMAP *hBitmap,HPALETTE *hPal)
// lpstrFile = pointer to name of bitmap file
// hBitmap = bitmap handle to return new bitmap in
// hPal = palette handle for new palette
// only needed for 256 color images
{
int i,fp; // loop counter and file handle
int numEntries; // number of palette entries in bitmap
HGLOBAL hGlb; // global handle used to read in bitmap data
LPBYTE bmpData; // pointer to global memory for bitmap data
LPBYTE dataBits; // pointer to actual bitmap picture data
BITMAPFILEHEADER bmfh; // bitmap file header
LPBITMAPINFOHEADER bmih; // pointer to bitmap info header
HDC hDC; // device context used to create hBitmap
LOGPALETTE *LogPal=NULL; // memory pointer to store logical palette in
LPRGBQUAD lpRGB; // pointer to RGB quad structures of bitmap
OFSTRUCT datafile;
if (!hBitmap)
{ErrorMsg(hwnd,"Invalid parameter");
return FALSE;
}
// open bitmap file
fp = OpenFile(lpstrFile,(LPOFSTRUCT)&datafile,OF_READ);
if (fp==-1)
{// ErrorMsg(hwnd,lpstrFile);
ErrorMsg(hwnd,"Unable to open .BMP file");
return FALSE;
}
// read in bitmap file header
_lread(fp,(LPSTR)&bmfh,sizeof(BITMAPFILEHEADER));
// verify file is type BM (bitmap file)
if (bmfh.bfType!=0x4D42)
{_lclose(fp);
ErrorMsg(hwnd,"Invalid file");
return FALSE;
}
// allocate global memory to store bitmap data in
hGlb = GlobalAlloc(GHND,filelength(fp));
bmpData = (LPBYTE)GlobalLock(hGlb);
// verify memory properly allocated
if (!bmpData)
{if (hGlb) GlobalFree(hGlb);
_lclose(fp);
ErrorMsg(hwnd,"Memory allocation failed");
return FALSE;
}
// read in bitmap
_hread(fp,(LPSTR)bmpData,bmfh.bfSize-sizeof(BITMAPFILEHEADER));
_lclose(fp); // no longer need file handle
// get pointer to bitmap info header
bmih = (LPBITMAPINFOHEADER)bmpData;
// get pointer to actual bitmap data
dataBits =
(LPBYTE)((LONG)bmpData+(LONG)bmfh.bfOffBits-sizeof(BITMAPFILEHEADER));
// get pointer to RGB quad structures
lpRGB = (LPRGBQUAD)((LONG)bmih+sizeof(BITMAPINFOHEADER));
// determine the number of palette entries based on number of colors
if (bmih->biBitCount==1) numEntries = 2;
else if (bmih->biBitCount==4) numEntries = 16;
else if (bmih->biBitCount==8) numEntries = 256;
else if (bmih->biBitCount==24) numEntries = 0; // no palette for 24 bit
// get a screen device context
hDC = GetDC(NULL);
// read in logical palette
if (numEntries&&hPal)
{// get memory to read palette into
LogPal =
(LOGPALETTE*)LocalAlloc(LPTR,
sizeof(LOGPALETTE)+numEntries*sizeof(PALETTEENTRY));
if (LogPal==NULL)
{ErrorMsg(hwnd,"Memory allocation failed LogPal");
return FALSE;
}
// setup logpalette structure
LogPal->palVersion = 0x300;
LogPal->palNumEntries = numEntries;
for (i=0;i<numEntries;i++)
{LogPal->palPalEntry[i].peRed = lpRGB[i].rgbRed;
LogPal->palPalEntry[i].peGreen = lpRGB[i].rgbGreen;
LogPal->palPalEntry[i].peBlue = lpRGB[i].rgbBlue;
LogPal->palPalEntry[i].peFlags = 0;
}
// create the palette using the bitmap's logical palette
*hPal = CreatePalette((LPLOGPALETTE)LogPal);
// set palette into the device context
SelectPalette(hDC,*hPal,TRUE);
RealizePalette(hDC);
}
else if (hPal) *hPal = NULL;
// create the bitmap in the device context
*hBitmap = CreateDIBitmap(hDC,bmih,CBM_INIT,(LPSTR)dataBits,
(LPBITMAPINFO)bmih,DIB_RGB_COLORS);
// perform cleanup
ReleaseDC(NULL,hDC);
if (LogPal) LocalFree((LOCALHANDLE)LogPal); // my LOCALHANDLE addition
GlobalUnlock(hGlb);
GlobalFree(hGlb);
// verify bitmap created
if(!*hBitmap)
{if (hPal&&*hPal) DeleteObject(*hPal);
ErrorMsg(hwnd,"Create bitmap failure");
return FALSE;
}
return TRUE;
}
BOOL FAR PASCAL DrawBitmap(HWND hwnd,HBITMAP hBitmap,
HPALETTE hPal,HDC hDC,int x,int y)
// hBitmap = handle of bitmap to be drawn
// hPal = palette of bitmap, if necessary (may ne NULL)
// hDC = device context bitmap to be drawn on
// x,y = location bitmap to be drawn on device context
{
BITMAP bitmap; // structure to hold bitmap statistics
HDC hDCMem; // memory DC to place bitmap in
POINT bSize,origin; //
RECT cRect;
if (!hBitmap || !hDC)
{ErrorMsg(hwnd,"Invalid parameter");
return FALSE;
}
GetClientRect(hwnd,&cRect);
// create a compatable memory dc to place bitmap in
hDCMem = CreateCompatibleDC(hDC);
// selete bitmap into memory DC
SelectObject(hDCMem,hBitmap);
// set mapping modes to be equivalent
SetMapMode(hDCMem,GetMapMode(hDC));
// get statistics of bitmap
GetObject(hBitmap,sizeof(BITMAP),(LPSTR)&bitmap);
// convert size and origin of bitmap to logical coordinates
bSize.x = bitmap.bmWidth;
bSize.y = bitmap.bmHeight;
DPtoLP(hDC,&bSize,1);
origin.x = origin.y = 0;
DPtoLP(hDCMem,&origin,1);
// if palette is provided, set dc to use it
if (hPal)
{SelectPalette(hDC,hPal,FALSE);
RealizePalette(hDC);
}
// draw bitmap onto passed in device context
if (x<0&&y<0)
BitBlt(hDC,(WIDTH(cRect)-bSize.x)/2,(HEIGHT(cRect)-40-bSize.y)/2,bSize.x,bSize.y,hDCMem,origin.x,origin.y,SRCCOPY);
else
BitBlt(hDC,x,y,bSize.x,bSize.y,hDCMem,origin.x,origin.y,SRCCOPY);
// cleanup
DeleteDC(hDCMem);
return TRUE;
}
void parser(char *line,char *temp,UINT linelength)
{
int i=0;
for (i=0;i<=linelength;i++)
{
*(temp+i) = *(line+i);
if (*(temp+i)==' '||*(temp+i)==NULL)
{
*(temp+i) = NULL;
break;
}
}
}
int Read_Title(HWND hWnd,HFILE hFile)
{
char lineBuf[128],temp[128],original[128];
char *token[6],fontname[32],fontsize[4];
int i,j,x,y,nLineSpacing,flag=TRUE;
UINT linelength;
DWORD fontcolor;
char color[32];
HDC hDC;
LOGFONT lf;
TEXTMETRIC tm;
HFONT hFont;
strcpy(fontname,"Roman");
strcpy(fontsize,"12");
fontcolor = BLACK;
while (GetaLine(hFile,lineBuf,&linelength))
{
if (lineBuf[0]=='<'&&lineBuf[1]=='T') break;
}
if (lineBuf[0]!='<'||lineBuf[1]!='T') return FALSE;
hDC = GetDC(hWnd);
while (GetaLine(hFile,lineBuf,&linelength))
{if (linelength==0) break;
lineBuf[linelength] = NULL; strcpy(original,lineBuf);
// BWCCMessageBox(hWnd,lineBuf,"Test",MB_OK | MB_ICONINFORMATION);
token[0] = strtok(lineBuf," ");
parser(token[0],temp,linelength);
if (strcmp(temp,"(Font)")==0)
{
token[1] = strtok(NULL," ");
parser(token[1],fontname,linelength);
continue;
}
if (strcmp(temp,"(Color)")==0)
{
token[1] = strtok(NULL," ");
parser(token[1],color,linelength);
if (strcmp(color,"BLACK")==0) fontcolor = BLACK; else
if (strcmp(color,"BLUE")==0) fontcolor = BLUE; else
if (strcmp(color,"GREEN")==0) fontcolor = GREEN; else
if (strcmp(color,"CYAN")==0) fontcolor = CYAN; else
if (strcmp(color,"RED")==0) fontcolor = RED; else
if (strcmp(color,"MAGENTA")==0) fontcolor = MAGENTA; else
if (strcmp(color,"BROWN")==0) fontcolor = BROWN; else
if (strcmp(color,"LIGHTGRAY")==0) fontcolor = LIGHTGRAY; else
if (strcmp(color,"GRAY")==0) fontcolor = GRAY; else
if (strcmp(color,"LIGHTBLUE")==0) fontcolor = LIGHTBLUE; else
if (strcmp(color,"LIGHTGREEN")==0) fontcolor = LIGHTGREEN; else
if (strcmp(color,"LIGHTCYAN")==0) fontcolor = LIGHTCYAN; else
if (strcmp(color,"LIGHTRED")==0) fontcolor = LIGHTRED; else
if (strcmp(color,"LIGHTMAGENTA")==0) fontcolor = LIGHTMAGENTA; else
if (strcmp(color,"YELLOW")==0) fontcolor = YELLOW; else
if (strcmp(color,"WHITE")==0) fontcolor = WHITE;
continue;
}
if (strcmp(temp,"(Size)")==0)
{
token[1] = strtok(NULL," ");
parser(token[1],fontsize,linelength);
continue;
}
if (strcmp(temp,"(Position)")==0)
{
token[1] = strtok(NULL," ");
parser(token[1],temp,linelength);
x = atoi(temp);
token[2] = strtok(NULL," ");
parser(token[2],temp,linelength);
y = atoi(temp);
continue;
}
if (flag)
{lf.lfHeight = atoi(fontsize);
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_NORMAL;
lf.lfItalic = 0;
lf.lfUnderline = 0;
lf.lfStrikeOut = 0;
lf.lfCharSet = ANSI_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_ROMAN;
strcpy(lf.lfFaceName,fontname);
hFont = CreateFontIndirect(&lf);
SelectObject(hDC,hFont);
SetTextColor(hDC,fontcolor);
GetTextMetrics(hDC,&tm);
nLineSpacing = tm.tmHeight + tm.tmExternalLeading;
flag = FALSE;
}
TextOut(hDC,x,y,original,linelength);
TextOut(hmemDC,x,y,original,linelength);
y += nLineSpacing; // move down a line
}
ReleaseDC(hWnd,hDC);
DeleteObject(hFont);
return TRUE;
}
int Read_Image(HWND hWnd,HFILE hFile)
{
char lineBuf[128],temp[128],original[128];
char *token[6];
int i,j,x,y;
UINT linelength;
HDC hDC;
HBITMAP hBitmap;
HPALETTE hPal;
while (GetaLine(hFile,lineBuf,&linelength))
{
if (lineBuf[0]=='<'&&lineBuf[1]=='I') break;
}
if (lineBuf[0]!='<'||lineBuf[1]!='I') return FALSE;
hDC = GetDC(hWnd);
while (GetaLine(hFile,lineBuf,&linelength))
{if (linelength==0) break;
lineBuf[linelength] = NULL; strcpy(original,lineBuf);
// BWCCMessageBox(hWnd,lineBuf,"Test",MB_OK | MB_ICONINFORMATION);
token[0] = strtok(lineBuf," ");
parser(token[0],temp,linelength);
if (strcmp(temp,"(Position)")==0)
{
token[1] = strtok(NULL," ");
parser(token[1],temp,linelength);
x = atoi(temp); // TextOut(hDC,500,350,temp,strlen(temp));
token[2] = strtok(NULL," ");
parser(token[2],temp,linelength);
y = atoi(temp); // TextOut(hDC,500,370,temp,strlen(temp));
continue;
}
CreateBitmapFromFile(hWnd,original,&hBitmap,&hPal);
DrawBitmap(hWnd,hBitmap,hPal,hDC,x,y);
BitBlt(hmemDC,0,0,WIDTH(cRect),HEIGHT(cRect),hDC,0,0,SRCCOPY);
DeleteObject(hBitmap);
DeleteObject(hPal);
}
ReleaseDC(hWnd,hDC);
return TRUE;
}
int Read_Buttons(HWND hWnd,HFILE hFile)
{
char lineBuf[128],temp[128];
int i,xPos,count=0,index=0;
UINT linelength;
HDC hDC;
HANDLE hInstance;
HMENU hMenuTemp;
RECT cRect;
GetClientRect(hWnd,&cRect); xPos = 5;
hInstance = GetWindowWord(hWnd,GWW_HINSTANCE);
CreateWindow("BUTTON","Exit",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
530,425,100,30,hWnd,MY_EXIT,hInstance,NULL);
while (GetaLine(hFile,lineBuf,&linelength))
{
if (lineBuf[0]=='['&&lineBuf[1]=='B') break;
}
if (lineBuf[0]!='['||lineBuf[1]!='B') return FALSE;
hDC = GetDC(hWnd);
while (GetaLine(hFile,lineBuf,&linelength))
{if (linelength==0)
{
break;
}
lineBuf[linelength] = NULL;
if (strcmp(lineBuf,"Images")==0) hMenuTemp = MY_IMAGES_BUTTON; else
if (strcmp(lineBuf,"Video")==0) hMenuTemp = MY_VIDEO_BUTTON; else
if (strcmp(lineBuf,"Voice")==0) hMenuTemp = MY_VOICE_BUTTON; else
{
if (index>7) continue;
strcpy(TextButton[index],lineBuf);
switch (index)
{
case 0: hMenuTemp = MY_TEXT_BUTTON_0; break;
case 1: hMenuTemp = MY_TEXT_BUTTON_1; break;
case 2: hMenuTemp = MY_TEXT_BUTTON_2; break;
case 3: hMenuTemp = MY_TEXT_BUTTON_3; break;
case 4: hMenuTemp = MY_TEXT_BUTTON_4; break;
case 5: hMenuTemp = MY_TEXT_BUTTON_5; break;
case 6: hMenuTemp = MY_TEXT_BUTTON_6; break;
case 7: hMenuTemp = MY_TEXT_BUTTON_7; break;
case 8: hMenuTemp = MY_TEXT_BUTTON_8; break;
}
index++;
}
if (count==0)
{CreateWindow("BUTTON",lineBuf,
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
xPos,425,100,30,hWnd,hMenuTemp,hInstance,NULL);
xPos += 105;
if (xPos+205>WIDTH(cRect)) {count++; xPos = 5;}
}
else
{CreateWindow("BUTTON",lineBuf,
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
xPos,390,100,30,hWnd,hMenuTemp,hInstance,NULL);
xPos += 105;
if (xPos+100>WIDTH(cRect)) break;
}
}
ReleaseDC(hWnd,hDC);
return TRUE;
}
void Create_Child(HWND hWnd)
{
HANDLE hInstance;
HWND hChild;
hInstance = GetWindowWord(hWnd,GWW_HINSTANCE);
hChild = CreateWindow("ChildClass"," ",
WS_POPUP | WS_VSCROLL
// | WS_CAPTION | WS_MAXIMIZE | WS_SYSMENU,
,
0,0,640,480,
hWnd,NULL,hInstance,NULL);
ShowWindow(hChild,SW_SHOWNORMAL);
SetFocus(hChild);
}
int Read_Text(HWND hWnd,HFILE hFile,char *string)
{ // action=0 will text fit action=1 write text
char lineBuf[128],temp[128],original[128];
char *token[6],fontname[32],fontsize[4];
int i,j,x,y,flag=TRUE;
UINT linelength;
DWORD fontcolor;
char color[32];
HDC hDC;
LOGFONT lf;
TEXTMETRIC tm;
RECT cRect;
strcpy(fontname,"Roman");
strcpy(fontsize,"20");
fontcolor = BLACK;
nNumLines = 0;
x = 10; y = 35; hDC = GetDC(hWnd);
GetClientRect(hWnd,&cRect);
while (GetaLine(hFile,lineBuf,&linelength))
{
// lineBuf[linelength] = NULL;
if (strcmp(lineBuf,string)==0) break;
}
if (strcmp(lineBuf,string)!=0) return FALSE;
while (GetaLine(hFile,lineBuf,&linelength))
{/*if (linelength==0) break; */
// lineBuf[linelength] = NULL;
strcpy(original,lineBuf);
token[0] = strtok(lineBuf," ");
parser(token[0],temp,linelength);
if (strcmp(temp,string)==0) break;
if (strcmp(temp,"(Font)")==0)
{
token[1] = strtok(NULL," ");
parser(token[1],fontname,linelength);
continue;
}
if (strcmp(temp,"(Color)")==0)
{
token[1] = strtok(NULL," ");
parser(token[1],color,linelength);
if (strcmp(color,"BLACK")==0) fontcolor = BLACK; else
if (strcmp(color,"BLUE")==0) fontcolor = BLUE; else
if (strcmp(color,"GREEN")==0) fontcolor = GREEN; else
if (strcmp(color,"CYAN")==0) fontcolor = CYAN; else
if (strcmp(color,"RED")==0) fontcolor = RED; else
if (strcmp(color,"MAGENTA")==0) fontcolor = MAGENTA; else
if (strcmp(color,"BROWN")==0) fontcolor = BROWN; else
if (strcmp(color,"LIGHTGRAY")==0) fontcolor = LIGHTGRAY; else
if (strcmp(color,"GRAY")==0) fontcolor = GRAY; else
if (strcmp(color,"LIGHTBLUE")==0) fontcolor = LIGHTBLUE; else
if (strcmp(color,"LIGHTGREEN")==0) fontcolor = LIGHTGREEN; else
if (strcmp(color,"LIGHTCYAN")==0) fontcolor = LIGHTCYAN; else
if (strcmp(color,"LIGHTRED")==0) fontcolor = LIGHTRED; else
if (strcmp(color,"LIGHTMAGENTA")==0) fontcolor = LIGHTMAGENTA; else
if (strcmp(color,"YELLOW")==0) fontcolor = YELLOW; else
if (strcmp(color,"WHITE")==0) fontcolor = WHITE;
continue;
}
if (strcmp(temp,"(Size)")==0)
{
token[1] = strtok(NULL," ");
parser(token[1],fontsize,linelength);
continue;
}
if (strcmp(temp,"(Position)")==0)
{
token[1] = strtok(NULL," ");
parser(token[1],temp,linelength);
x = atoi(temp);
token[2] = strtok(NULL," ");
parser(token[2],temp,linelength);
y = atoi(temp);
continue;
}
if (flag)
{
lf.lfHeight = atoi(fontsize);
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_NORMAL;
lf.lfItalic = 0;
lf.lfUnderline = 0;
lf.lfStrikeOut = 0;
lf.lfCharSet = ANSI_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_ROMAN;
strcpy(lf.lfFaceName,fontname);
hFontText = CreateFontIndirect(&lf);
SelectObject(hDC,hFontText);
SetTextColor(hDC,fontcolor);
GetTextMetrics(hDC,&tm);
nLineSpacing = tm.tmHeight + tm.tmExternalLeading;
flag = FALSE;
}
strcpy(Text[nNumLines],original);
nNumLines++; y += nLineSpacing;
}
ReleaseDC(hWnd,hDC);
DeleteObject(hFontText);
if (y<HEIGHT(cRect)) return FALSE; else return nNumLines;
}
int GetFileName(HWND hWnd,HFILE hFile,char *string)
{
char lineBuf[128];
UINT linelength;
while (GetaLine(hFile,lineBuf,&linelength))
{
if (strcmp(lineBuf,string)==0) break;
}
if (strcmp(lineBuf,string)!=0) return FALSE;
GetaLine(hFile,szString,&linelength);
}
#pragma argsused
int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASS wndclass;
if (!hPrevInstance)
{
wndclass.style =CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc =WndProc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =hInstance;
wndclass.hIcon =LoadIcon(hInstance,"Resume");
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName ="MENU_1";
wndclass.lpszClassName ="MyClass";
if (!RegisterClass(&wndclass)) return (0);
wndclass.style =CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndclass.lpfnWndProc =ChildProc;
wndclass.hIcon =NULL;
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName ="ChildClass";
if (!RegisterClass(&wndclass))
{
ErrorMsg(hWnd,"Could not register editor child window");
return(0);
}
}
hWnd = CreateWindow("MyClass",szProgName,
// WS_OVERLAPPEDWINDOW,
WS_MAXIMIZE | WS_SYSMENU | WS_MINIMIZEBOX,
0,
0,
640,
480,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
long FAR PASCAL _export WndProc(HWND hWnd,UINT wMessage,UINT wParam,LONG lParam)
{
HBRUSH hBrush,hOldBrush,hmemOldBrush;
HPEN hPen,hOldPen,hmemOldPen;
HBITMAP hBitmap,hOldBitmap,hmemOldBitmap;
HDC hDC;
HPALETTE hPal;
// HDIB hDIB;
HFONT hFont;
HCURSOR hCursor,hOldCursor;
PAINTSTRUCT ps;
static POINT ptBegin,ptEnd;
OPENFILENAME ofn;
static HWND hChild = NULL,hImage = NULL;
HANDLE hInstance;
char temp[128];
HFILE hFile;
PCXHEAD pcxHd;
int i,j,length;
static int ydist;
// static PALETTEENTRY peEntry[256];
static COLORREF crColor = RGB(0,128,0);
LPCSTR szFilter[] = {"All files (*.*)","*.*",
"BMP files (*.BMP)","*.BMP",
"PCX files (*.PCX)","*.PCX",
""};
CHOOSECOLOR cc;
static DWORD dwCustColors[16]= {
RGB(0, 0, 0), /* black */ /* Almost Standard VGA 16 color */
RGB(0, 0,0xC0), /* blue */
RGB(0,0xC0, 0), /* green */
RGB( 0,0xC0,0xC0), /* cyan */
RGB(0xC0, 0, 0), /* red */
RGB(0xC0, 0,0xC0), /* magenta */
RGB(0xFF,0xC0,0xA0), /* flesh */
RGB(0xC0,0xC0,0xC0), /* lt gray */
RGB(0x5C,0x5C,0x5C), /* gray */
RGB(0x3F,0x3F,0xFF), /* lt blue */
RGB(0x3F,0xFF,0x3F), /* lt green */
RGB(0x3F,0xFF,0xFF), /* lt cyan */
RGB(0xFF,0x3F,0x3F), /* lt red */
RGB(0xFF,0x3F,0xFF), /* lt magenta */
RGB(0xFF,0xFF,0x3F), /* yellow */
RGB(0xFF,0xFF,0xFF)}; /* white */
cc.lStructSize = sizeof(CHOOSECOLOR);
cc.hwndOwner = hWnd;
cc.hInstance = NULL;
cc.rgbResult = crColor;
cc.lpCustColors = dwCustColors;
cc.Flags = CC_RGBINIT | CC_FULLOPEN;
cc.lCustData = 0L;
cc.lpfnHook = NULL;
cc.lpTemplateName = NULL;
switch(wMessage)
{
case WM_COMMAND:switch (wParam)
{
case MY_TEXT_BUTTON_0:strcpy(ButtonTitle,TextButton[0]);
Create_Child(hWnd); break;
case MY_TEXT_BUTTON_1:strcpy(ButtonTitle,TextButton[1]);
Create_Child(hWnd); break;
case MY_TEXT_BUTTON_2:strcpy(ButtonTitle,TextButton[2]);
Create_Child(hWnd); break;
case MY_TEXT_BUTTON_3:strcpy(ButtonTitle,TextButton[3]);
Create_Child(hWnd); break;
case MY_TEXT_BUTTON_4:strcpy(ButtonTitle,TextButton[4]);
Create_Child(hWnd); break;
case MY_TEXT_BUTTON_5:strcpy(ButtonTitle,TextButton[5]);
Create_Child(hWnd); break;
case MY_TEXT_BUTTON_6:strcpy(ButtonTitle,TextButton[6]);
Create_Child(hWnd); break;
case MY_TEXT_BUTTON_7:strcpy(ButtonTitle,TextButton[7]);
Create_Child(hWnd); break;
case MY_TEXT_BUTTON_8:strcpy(ButtonTitle,TextButton[8]);
Create_Child(hWnd); break;
case MY_IMAGES_BUTTON:strcpy(ButtonTitle,"Images");
Create_Child(hWnd);
break;
case MY_VIDEO_BUTTON:strcpy(ButtonTitle,"Video");
Create_Child(hWnd);
break;
case MY_VOICE_BUTTON:hFile = _lopen(szPath,READ);
if (hFile == HFILE_ERROR) break;
GetFileName(hWnd,hFile,"(Voice)");
_lclose(hFile);
sndPlaySound(szString,SND_ASYNC);
break;
case MY_EXIT: SendMessage(hWnd,WM_CLOSE,0,0L);
break;
}
break;
case WM_LBUTTONDOWN:
break;
case WM_LBUTTONUP:/* if (wParam & MK_RBUTTON)
{hFile = _lopen(szPath,READ);
if (hFile == HFILE_ERROR)
{
wsprintf(temp,"\n %s Resume.txt file not found",szPath);
BWCCMessageBox(hWnd,temp,"Error",MB_OK | MB_ICONINFORMATION);
SendMessage(hWnd,WM_CLOSE,0,0L);
}
Read_Title(hWnd,hFile);
_llseek(hFile,0L,0);
Read_Image(hWnd,hFile);
_lclose(hFile);
} */
break;
case WM_MOUSEMOVE:if (wParam & MK_LBUTTON)
{
}
break;
case WM_CREATE:GetClientRect(hWnd,&cRect);
hDC = GetDC(hWnd);
hmemDC = CreateCompatibleDC(hDC);
hmemBitmap = CreateCompatibleBitmap(hDC,WIDTH(cRect),HEIGHT(cRect));
hmemOldBitmap = SelectObject(hmemDC,hmemBitmap);
hPen = CreatePen(PS_SOLID,1,RGB(255,255,255));
hBrush = CreateSolidBrush(RGB(255,255,255));
SelectObject(hmemDC,hPen);
SelectObject(hmemDC,hBrush);
Rectangle(hmemDC,0,0,WIDTH(cRect),HEIGHT(cRect));
DeleteObject(hBrush);
DeleteObject(hPen);
hFile = _lopen(szPath,READ);
if (hFile == HFILE_ERROR)
{
wsprintf(temp,"\n %s Resume.txt file not found",szPath);
BWCCMessageBox(hWnd,temp,"Error",MB_OK | MB_ICONINFORMATION);
SendMessage(hWnd,WM_CLOSE,0,0L);
}
Read_Buttons(hWnd,hFile);
_lclose(hFile);
ReleaseDC(hWnd,hDC);
sndPlaySound("CHIMES.WAV",SND_ASYNC);
break;
case WM_MOVE:/* MessageBox(hWnd,"WM_MOVE",szProgName,MB_OK); */break;
case WM_SIZE:/* MessageBox(hWnd,"WM_SIZE",szProgName,MB_OK); */break;
case WM_PAINT:hDC = BeginPaint(hWnd,&ps);
// MessageBox(hWnd,"WM_PAINT",szProgName,MB_OK);
GetClientRect(hWnd,&cRect);
hFile = _lopen(szPath,READ);
if (hFile == HFILE_ERROR) SendMessage(hWnd,WM_CLOSE,0,0L);
while (Read_Title(hWnd,hFile)) {}
_llseek(hFile,0L,0);
while (Read_Image(hWnd,hFile)) {}
_lclose(hFile);
// BitBlt not needed - this needs cleaning up
BitBlt(hDC,0,0,WIDTH(cRect),HEIGHT(cRect),hmemDC,0,0,SRCCOPY);
EndPaint(hWnd,&ps);
break;
case WM_CLOSE:if (BWCCMessageBox(hWnd,"\n\n Exit, are you sure?",szProgName,
MB_YESNO | MB_ICONQUESTION)==IDYES)
{if (Shareware)
{
WinHelp(hWnd,"resume.hlp",HELP_KEY,(DWORD)(LPSTR)"Registration");
}
DeleteObject(hmemBitmap);
DeleteDC(hmemDC);
DestroyWindow(hWnd);
}
break;
case WM_DESTROY:PostQuitMessage(0);break;
default: return DefWindowProc(hWnd,wMessage,wParam,lParam);
}
return (0L);
}
long FAR PASCAL ChildProc(HWND hChild,UINT wMessage,UINT wParam,LONG lParam)
{
PAINTSTRUCT ps;
HANDLE hInstance;
static HFONT hFont;
HFILE hFile;
HBITMAP hBitmap;
HPALETTE hPal;
HDC hDC;
TEXTMETRIC tm;
RECT cRect;
DWORD TextColor;
char temp[128];
int i,j;
UINT linelength;
// int VertOldPos=0,VertScrollPos=0,VertMaxScroll;
static int yChar,yPage,xPage,yPos;
LPSTR *lpImage;
// This function has a private DC, do not use ReleaseDC();
switch (wMessage)
{
case WM_COMMAND:
switch (wParam)
{case MY_EDIT_RETURN:mciSendString("close all",achString,128,hChild);
SendMessage(hChild,WM_CLOSE,0,0L);
break;
case MY_VIDEO_PLAY:if (strcmp(ButtonTitle,"Video")==0)
{
mciSendString("play The_AVI",achString,128,hChild);
}
break;
case MY_VIDEO_PAUSE:mciSendString("pause The_AVI",achString,128,hChild);
break;
case MY_VIDEO_REWIND:mciSendString("seek The_AVI to start",achString,128,hChild);
break;
case MY_IMAGE_NEXT:nImageNum++;
if (nImageNum>=nNumImages) nImageNum = 0;
InvalidateRect(hChild,NULL,TRUE);
// wsprintf(temp,"nImageNum = %d nNumImages = %d",nImageNum,nNumImages);
// BWCCMessageBox(hChild,temp,"Testing",MB_OK | MB_ICONINFORMATION);
break;
case MY_IMAGE_BACK:nImageNum--;
if (nImageNum<0) nImageNum = nNumImages-1;
InvalidateRect(hChild,NULL,TRUE);
break;
}
break;
case WM_CREATE:hInstance = GetWindowWord(hChild,GWW_HINSTANCE);
GetClientRect(hChild,&cRect);
CreateWindow("BUTTON","Return",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
WIDTH(cRect)-90,HEIGHT(cRect)-40,80,30,
hChild,MY_EDIT_RETURN,hInstance,NULL);
if (strcmp(ButtonTitle,"Video")==0)
{
CreateWindow("BUTTON","Play",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
WIDTH(cRect)-180,HEIGHT(cRect)-40,80,30,
hChild,MY_VIDEO_PLAY,hInstance,NULL);
CreateWindow("BUTTON","Pause",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
WIDTH(cRect)-270,HEIGHT(cRect)-40,80,30,
hChild,MY_VIDEO_PAUSE,hInstance,NULL);
CreateWindow("BUTTON","Rewind",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
WIDTH(cRect)-360,HEIGHT(cRect)-40,80,30,
hChild,MY_VIDEO_REWIND,hInstance,NULL);
strcpy(temp,"open ");
hFile = _lopen(szPath,READ);
if (hFile == HFILE_ERROR) break;
GetFileName(hChild,hFile,"(Video)");
_lclose(hFile);
strcat(temp,szString);
strcat(temp," alias The_AVI");
mciSendString(temp,achString,128,hChild);
mciSendString("put The_AVI window at 120 120 0 0",achString,128,hChild);
}
if (strcmp(ButtonTitle,"Images")==0)
{
CreateWindow("BUTTON","Next",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
WIDTH(cRect)-180,HEIGHT(cRect)-40,80,30,
hChild,MY_IMAGE_NEXT,hInstance,NULL);
CreateWindow("BUTTON","Back",
WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
WIDTH(cRect)-270,HEIGHT(cRect)-40,80,30,
hChild,MY_IMAGE_BACK,hInstance,NULL);
// get list of images
hFile = _lopen(szPath,READ);
if (hFile == HFILE_ERROR) SendMessage(hChild,WM_CLOSE,0,0L);
strcpy(temp,"("); strcat(temp,ButtonTitle); strcat(temp,")");
while (GetaLine(hFile,szString,&linelength))
{
if (strcmp(szString,temp)==0) break;
}
if (strcmp(szString,temp)!=0) SendMessage(hChild,WM_CLOSE,0,0L);
nImageNum = 0; nNumImages = 0;
while (GetaLine(hFile,szString,&linelength))
{
if (linelength<3) break;
lstrcpy(images[nNumImages],szString);
GetaLine(hFile,szString,&linelength);
if (linelength<3) break;
lstrcpy(captions[nNumImages++],szString);
}
// wsprintf(temp,"nImageNum = %d nNumImages = %d",nImageNum,nNumImages);
// BWCCMessageBox(hChild,temp,"Testing",MB_OK | MB_ICONINFORMATION);
_lclose(hFile);
}
hDC = GetDC(hChild);
if (strcmp(ButtonTitle,"Video")!=0&&strcmp(ButtonTitle,"Images")!=0)
{
hFile = _lopen(szPath,READ);
if (hFile == HFILE_ERROR) SendMessage(hChild,WM_CLOSE,0,0L);
strcpy(temp,"("); strcat(temp,ButtonTitle); strcat(temp,")");
VertOldPos = 0; VertScrollPos = 0;
VertMaxScroll = Read_Text(hChild,hFile,temp);
_lclose(hFile);
GetClientRect(hChild,&cRect);
VertMaxScroll -= (HEIGHT(cRect)-40)/nLineSpacing;
if (VertMaxScroll<0) VertMaxScroll = 0;
SetScrollRange(hChild,SB_VERT,0,VertMaxScroll,FALSE);
SetScrollPos(hChild,SB_VERT,0,TRUE);
}
else
{
VertMaxScroll = 0;
SetScrollRange(hChild,SB_VERT,0,VertMaxScroll,FALSE);
SetScrollPos(hChild,SB_VERT,0,TRUE);
}
break;
case WM_VSCROLL:
switch(wParam)
{
case SB_THUMBPOSITION:
VertOldPos = VertScrollPos;
VertScrollPos = LOWORD(lParam);
break;
case SB_LINEDOWN:
VertOldPos = VertScrollPos;
VertScrollPos++;
VertScrollPos = VertScrollPos > VertMaxScroll ?
VertMaxScroll : VertScrollPos;
break;
case SB_LINEUP:
VertOldPos = VertScrollPos;
VertScrollPos--;
VertScrollPos = VertScrollPos < 0 ? 0 : VertScrollPos;
break;
case SB_PAGEDOWN:
VertOldPos = VertScrollPos;
VertScrollPos += 10;
VertScrollPos = VertScrollPos > VertMaxScroll ?
VertMaxScroll : VertScrollPos;
break;
case SB_PAGEUP:
VertOldPos = VertScrollPos;
VertScrollPos -= 10;
VertScrollPos = VertScrollPos < 0 ? 0 : VertScrollPos;
break;
}
SetScrollPos(hChild,SB_VERT,VertScrollPos,TRUE);
InvalidateRect(hChild,NULL,TRUE);
break;
case WM_LBUTTONDOWN:break;
case WM_PAINT:
BeginPaint(hChild,&ps);
TextColor = GetTextColor(ps.hdc);
SetTextColor(ps.hdc,LIGHTBLUE);
TextOut(ps.hdc,10,10,ButtonTitle,strlen(ButtonTitle));
SetTextColor(ps.hdc,TextColor);
j = 0;
if (strcmp(ButtonTitle,"Video")!=0&&strcmp(ButtonTitle,"Images")!=0)
for (i=VertScrollPos;i<nNumLines;i++)
{
TextOut(ps.hdc,25,40+j*nLineSpacing,Text[i],strlen(Text[i]));
j++;
}
if (strcmp(ButtonTitle,"Images")==0)
{
lstrcpy(temp,images[nImageNum]);
// TextOut(ps.hdc,400,35,temp,strlen(temp));
CreateBitmapFromFile(hChild,temp,&hBitmap,&hPal);
DrawBitmap(hChild,hBitmap,hPal,ps.hdc,-1,-1);
BitBlt(hmemDC,0,0,WIDTH(cRect),HEIGHT(cRect),ps.hdc,0,0,SRCCOPY);
TextOut(ps.hdc,25,400,captions[nImageNum],strlen(captions[nImageNum]));
DeleteObject(hBitmap);
DeleteObject(hPal);
}
EndPaint(hChild,&ps);
break;
case WM_CLOSE:// DeleteObject(hFont);
DestroyWindow(hChild);
break;
default:return DefWindowProc(hChild,wMessage,wParam,lParam);
}
return(0);
}